<?php
/**
 * Created by PhpStorm.
 * User: 刚
 * Date: 2017/7/30
 * Time: 23:09
 */
class BookSingleton{

    private $author = 'Gamma, Helm, Johnson, and Vlissides';
    private $title = 'Design Patterns';
    private static $book = NULL;
    private static $isLoaneOut = FALSE;

    private function __construct()
    {
    }

    static function borrowBook()
    {
        if(FALSE == self::$isLoaneOut){
            if (NULL == self::$book){
                self::$book = new BookSingleton();
            }
            self::$isLoaneOut = TRUE;
            return self::$book;
        } else{
            return NUll;
        }
    }

    function returnBook(BookSingleton $bookSingleton){
        self::$isLoaneOut = FALSE;
    }

    function getAuthor(){
        return $this->author;
    }

    function getTitle(){
        return $this->title;
    }

    function getAuthorAndTitle(){
        return $this->getTitle() . 'by' . $this->getAuthor();
    }
}